package com.ids.actions;

import java.util.Map;
import com.ids.bean.UserInfo;
import com.ids.service.LoginService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class Login extends ActionSupport {

	private static final long serialVersionUID = 1L;
	private String empCode;
	private String password;


	public String execute() throws Exception {
		String empCode = getEmpCode();
		String password = getPassword();
		Map<String, Object> session = ActionContext.getContext().getSession();
		String forward = "error";
		LoginService loginService = new LoginService();
		UserInfo userInfo = loginService.getUserInfo(empCode, password);
		if (userInfo != null) {
			session.put("empCode", empCode);
			session.put("userInfo", userInfo);
			forward = "User";
			if (userInfo.getRole().equalsIgnoreCase("superadmin")) {
			forward = "admin";
			}
		}
			return forward;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getEmpCode() {
		return empCode;
	}

	public void setEmpCode(String empCode) {
		this.empCode = empCode;
	}
}
